"""
使用requests请求代理服务器
请求http和https网页均适用
"""


def get_proxy_poll(num=2):
    return [get_proxies() for _ in range(num)]


def get_proxies():
    import requests

    # 提取代理API接口，获取1个代理IP
    api_url = "https://dps.kdlapi.com/api/getdps/?secret_id=opibecnwc528dt8a6pch&signature=mfn488fljczs1vtcyjqwmtwqm75blvd1&num=1&sep=1"

    # 获取API接口返回的代理IP
    proxy_ip = requests.get(api_url).text

    # 用户名密码认证(私密代理/独享代理)
    username = "d4143676909"
    password = "0atxcgei"
    proxies = {
        "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip},
        "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip}
    }
    print(f'获取代理信息{proxies}')
    return proxies


if __name__ == '__main__':
    get_proxies()
